/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.site.console.action;

import java.util.Date;
import java.util.List;

import javax.inject.Inject;

import org.apache.commons.lang3.StringUtils;

import com.us.usws.model.domain.base.BaseVideoCat;
import com.us.usws.model.flat.system.DOUser;
import com.us.usws.service.cud.BaseVideoCatCUDService;
import com.us.usws.service.ro.BaseVideoCatROService;
import com.us.usws.support.uitls.JSONDataUtil;
import com.us.usws.support.uitls.SiteWebContext;
import com.us.usws.support.uitls.WebContext;

/**
 * Struts2 action
 * @author robot
 */
public class BaseVideoCatAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	private BaseVideoCat baseVideoCat;

	@Inject
	private BaseVideoCatROService baseVideoCatROService;

	@Inject
	private BaseVideoCatCUDService baseVideoCatCUDService;

	private String uids;
	
	private List<String> rateCatUids;

	/**
	 * ajax load the list of BaseVideoCat
	 */
	public void ajaxLoadBaseVideoCats() {
		getOut().println(JSONDataUtil.jsonStringfromObject(baseVideoCatROService.getAllBaseVideoCats()));
	}
	
	/**
	 * ajax load the list of BaseVideoCat
	 */
	public void ajaxLoadVideoCatTree() {
		getOut().println(JSONDataUtil.jsonStringfromObject(baseVideoCatROService.getVideoCatTree(rateCatUids)));
	}

	/**
	 * ajax update BaseVideoCat
	 */
	public void ajaxUpdateBaseVideoCat() {
		if (baseVideoCat != null) {
			Date now = new Date(System.currentTimeMillis());
			WebContext wc = new SiteWebContext(getRequest(), getResponse());
			DOUser user = wc.getUser();
			
			String uid = baseVideoCat.getUid();
			if (StringUtils.isNotBlank(uid)) {
				baseVideoCat.setLastUpdByUid(user.getUid());
				baseVideoCat.setLastUpdDate(now);
				baseVideoCatCUDService.updateBaseVideoCat(baseVideoCat);
			} else {
				baseVideoCat.setCreateByUid(user.getUid());
				baseVideoCat.setCreateDate(now);
				baseVideoCatCUDService.addBaseVideoCat(baseVideoCat);
			}
			getOut().print(true);
		} else {
			getOut().print(false);
		}
	}

	/**
	 * ajax delete user.
	 */
	public void ajaxDeleteBaseVideoCat() {
		baseVideoCatCUDService.deleteBaseVideoCatMore(uids);
	}

	public void setBaseVideoCat(BaseVideoCat baseVideoCat) {
		this.baseVideoCat = baseVideoCat;
	}

	public BaseVideoCat getBaseVideoCat() {
		return baseVideoCat;
	}

	public String getUids() {
		return uids;
	}

	public void setUids(String uids) {
		this.uids = uids;
	}

	public List<String> getRateCatUids() {
		return rateCatUids;
	}

	public void setRateCatUids(List<String> rateCatUids) {
		this.rateCatUids = rateCatUids;
	}
}